#include <stdio.h>
#include <stdlib.h>

typedef short int bool;
#define true    1
#define false   0

#define MAX 100

int queue[MAX] = {-1};
int qh = -1, qt = 0;

int ROW = 0, COL = 0;
char** area = NULL;

void init()
{
    int i = 0;
    area = (char**)malloc(ROW*sizeof(char*));
    for(i = 0; i < ROW; i++)
    {
        area[i] = (char*)malloc(COL*sizeof(char));
    }
}

void freearea()
{
    int i = 0;

    for(i = 0; i < ROW; i++)
    {
        free(area[i]);
    }
    free(area);
    area = NULL;
}

int getsite(int irow, int icol)
{
    return irow * COL + icol;
}

void getrc(int site, int* irow, int* icol)
{
    *irow = site / COL;
    *icol = site % COL;
}

void clearq()
{
    qh = 0;
    qt = 0;
}

bool isemptyq()
{
    if(qt == qh)
    {
        return true;
    }
    return false;
}

bool isfullq()
{
    if(qt == MAX)
    {
        return true;
    }
    return false;
}

bool putq(int val)
{
    if(isfullq())
    {
        return false;
    }
    queue[qt++] = val;
    return true;
}

bool getq(int* val)
{
    if(isemptyq())
    {
        return false;
    }
    *val = queue[qh++];
    return true;
}

int getnextsite()
{
    int SITE = 0;
    int irow = 0, icol = 0;

    while(SITE < ROW * COL)
    {
        getrc(SITE, &irow, &icol);

        if(area[irow][icol] == '@')
        {
            return SITE;
        }
        SITE++;
    }
    return -1;
}

bool testspot(int irow, int icol)
{
    if(irow < 0 || irow >= ROW)
    {
        return false;
    }
    if(icol < 0 || icol >= COL)
    {
        return false;
    }
    if(area[irow][icol] == '@')
    {
        return true;
    }
    return false;
}

void resetspot(int site)
{
    int irow = 0, icol = 0;

    getrc(site, &irow, &icol);
    area[irow][icol] = '*';
}

void testspotaround(int site)
{
    int irow = 0, icol = 0;
    int i = 0, j = 0;

    getrc(site, &irow, &icol);

    resetspot(site);

    for(i = irow-1; i <= irow+1; i++)
    {
        for(j = icol-1; j <= icol+1; )
        {
            if(testspot(i, j) == true)
            {
                putq(getsite(i, j));
                resetspot(getsite(i, j));
            }
            if(i == irow)
            {
                j += 2;
            }
            else
            {
                j += 1;
            }
        }
    }

}

void fn()
{
    int site = -1;
    while(!isemptyq())
    {
        getq(&site);
        testspotaround(site);
    }
}

void process()
{
    int site = -1;
    int oildc = 0;

//    int i = 0, j = 0;
//
//    for(i = 0; i < ROW; i++)
//    {
//        for(j = 0; j < COL; j++)
//        {
//            printf("%c", area[i][j]);
//        }
//        printf("\n");
//    }
//    printf("\n");

    while(1)
    {
        clearq();
        site = getnextsite();
        if(site == -1)
        {
            printf("%d\n", oildc);
            return;
        }

        putq(site);

        fn();

        oildc++;
    }
}

int main()
{
    //freopen("bin\\debug\\in.txt", "r", stdin);
    int i = 0, j = 0;
    char line[MAX+1];

    while(1)
    {
        scanf("%d%d", &ROW, &COL);
        if(ROW == 0 || COL == 0)
        {
            break;
        }
        init();
        for(i = 0; i < ROW; i++)
        {
            scanf("%s", line);
            for(j = 0; j < COL; j++)
            {
                area[i][j] = line[j];
            }
        }
        process();
        freearea();
    }

    return 0;
}
